import 'package:puppy_store/models/home_model.dart';

class PrimaryCategoryModel {
  final String? id;
  final String? name;
  final String? icon;

  PrimaryCategoryModel({this.id, this.name, this.icon});
  factory PrimaryCategoryModel.fromJson(Map<String, dynamic> json) {
    return PrimaryCategoryModel(
      id: json['id'],
      name: json['name'],
      icon: json['icon'],
    );
  }
}

// 二级分类数据模型 start-----------
class SecondaryCategoryModel {
  final String? id;
  final String? name;
  final String? picture;
  final List<SubCategoryModel>? children; // 子分类列表

  SecondaryCategoryModel({this.id, this.name, this.picture, this.children});
  factory SecondaryCategoryModel.fromJson(Map<String, dynamic> json) {
    // 处理children模型
    List? childrenJSON = json['children'];
    List<SubCategoryModel> children = [];
    if (childrenJSON != null) {
      childrenJSON.forEach((element) {
        children.add(SubCategoryModel.fromJson(element));
      });
    }

    return SecondaryCategoryModel(
      children: children,
      id: json['id'],
      name: json['name'],
      picture: json['picture'],
    );
  }
}

class SubCategoryModel {
  final String? id;
  final String? name;
  final String? picture;
  final String? parentId;
  final String? parentName;
  final String? categories;
  final String? brands;
  final String? saleProperties;
  final List<GoodsModel>? goods;

  SubCategoryModel({
    this.id,
    this.name,
    this.picture,
    this.parentId,
    this.parentName,
    this.categories,
    this.brands,
    this.saleProperties,
    this.goods,
  });
  factory SubCategoryModel.fromJson(Map<String, dynamic> json) {
    // 处理goods模型
    List? goodsJSON = json['goods'];
    List<GoodsModel> goods = [];
    if (goodsJSON != null) {
      goodsJSON.forEach((element) {
        goods.add(GoodsModel.fromJson(element));
      });
    }

    return SubCategoryModel(
      id: json['id'],
      name: json['name'],
      picture: json['picture'],
      parentId: json['parentId'],
      parentName: json['parentName'],
      categories: json['categories'],
      brands: json['brands'],
      saleProperties: json['saleProperties'],
      goods: goods,
    );
  }
}

// 二级分类数据模型 end-----------
